package com.system.demo.controller.paper;


import cn.dev33.satoken.annotation.SaCheckPermission;
import com.system.demo.entity.DTO.PaperSearchDTO;
import com.system.demo.entity.DTO.PaperSubmitApplicationDTO;
import com.system.demo.entity.database.Paper;
import com.system.demo.entity.excelFile.PaperDTOForExcel;
import com.system.demo.mapper.PaperSubmitMapper;
import com.system.demo.service.PaperService;
import com.system.demo.tool.ResponseResult;
import com.system.demo.utils.ExcelExportUtil;
import com.system.demo.utils.PaperDTOMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletResponse;
import java.io.*;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.Comparator;
import java.util.List;
import java.util.stream.Collectors;


@RestController
@RequestMapping("/Paper")
@SaCheckPermission("PaperApply")
public class PaperController {
    @Autowired
    private PaperService paperService;

    /**
     * 学生提交论文申请
     *
     * @param paperSubmitApplicationDTO
     * @return
     */
    @PostMapping("/submit")
    public ResponseResult<?> submit(@RequestBody PaperSubmitApplicationDTO paperSubmitApplicationDTO) {
        System.out.println(paperSubmitApplicationDTO);
        return paperService.PaperSumbit(paperSubmitApplicationDTO);
    }

    /**
     *学生在个人申请未被审批前可以删除个人申请
     * @param applicationId
     * @return
     */
    @PostMapping("/delete")
    public ResponseResult<?> delete(@RequestParam Integer applicationId) {
        return paperService.PaperDelete(applicationId);
    }

    /**
     * 学生按照学号查询个人论文申请信息
     * @param current
     * @param size
     * @return
     */
    @PostMapping("/usersearch")
    public ResponseResult<?> usersearch(@RequestParam int current, int size) {

        return paperService.PaperSearch(current, size);
    }

    /**
     * 学生上传论文证明材料以及期刊名
     * @param applicationId
     * @param file
     * @param topic 期刊名、专利机构、软著机构
     * @return
     */
    @PostMapping("/evidence")
    public ResponseResult<?> evidence(@RequestParam Integer applicationId, @RequestParam("file") MultipartFile file, @RequestParam String topic, @RequestParam String awardTime) {
        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
        LocalDateTime AwardTime = LocalDateTime.parse(awardTime, formatter);
        return paperService.PaperEvidence(applicationId, file, topic, AwardTime);
    }

    /**
     * 学生未获奖
     * @param applicationId
     * @return
     */
    @PostMapping("/NoAward")
    public ResponseResult<?> noAward(@RequestParam Integer applicationId) {
        return paperService.NoAward(applicationId);
    }

    /**
     * 新增一个在未审批之前可以修改的功能
     * @param applicationId
     * @param paperSubmitApplicationDTO
     * @return
     */
    @PostMapping("/Update")
    public ResponseResult<?> update(@RequestParam Integer applicationId, @RequestBody PaperSubmitApplicationDTO paperSubmitApplicationDTO) {
        return paperService.PaperUpdate(applicationId,paperSubmitApplicationDTO);
    }
}
